﻿/* Fix for IE bug on getBoundingClientRect in jQuery offset function */
/* based on original jQuery code, see jQuery offset.js file */

/* Note: this only suppresses the error */
/* Include this file after jQuery library */

if ("getBoundingClientRect" in document.documentElement)
    jQuery.fn.offset = function (options) {
        var elem = this[0];

        if (options) {
            return this.each(function (i) {
                jQuery.offset.setOffset(this, options, i);
            });
        }

        if (!elem || !elem.ownerDocument) {
            return null;
        }

        if (elem === elem.ownerDocument.body) {
            return jQuery.offset.bodyOffset(elem);
        }

        var box = safeGetBoundingClientRect(elem),
			doc = elem.ownerDocument,
			body = doc.body,
			docElem = doc.documentElement,
			win = safeGetWindow(doc),
			clientTop = docElem.clientTop || body.clientTop || 0,
			clientLeft = docElem.clientLeft || body.clientLeft || 0,
			scrollTop = (win.pageYOffset || jQuery.support.boxModel && docElem.scrollTop || body.scrollTop),
			scrollLeft = (win.pageXOffset || jQuery.support.boxModel && docElem.scrollLeft || body.scrollLeft),
			top = box.top + scrollTop - clientTop,
			left = box.left + scrollLeft - clientLeft;

        return { top: top, left: left };
    };

function safeGetBoundingClientRect(elem) {
    try {
        return elem.getBoundingClientRect();
    } catch (e) {
        return { top: 0, left: 0, right: 0, bottom: 0 };
    }
}

function safeGetWindow(doc) {
    try {
        return elem.getWindow(doc);
    } catch (e) {
        return { pageXOffset: 0, pageYOffset: 0 };
    }
}